package test.telosys.persistence.pmproxy;

import java.util.List;

import org.demo.vo.bean.Badge;
import org.telosys.persistence.PersistenceManager;
import org.telosys.persistence.impl.PersistenceManagerProxy;

public class ServiceC {

	// TODO : 
	// @Inject 
	PersistenceManager pm = new PersistenceManagerProxy();
	
	public void saveBadge(Badge badge, boolean errorSimulation) {
		System.out.println("saveBadge() / instance id : " + pm.getInstanceId() );
		pm.save(badge);
		
		if ( errorSimulation ) {
			System.out.println("===== EXCEPTION for tests");
			throw new RuntimeException("Error simulation for tests");
		}
	}
	
	public List<Badge> loadAllBadges(boolean errorSimulation) {
		System.out.println("loadAllBadges() / instance id : " + pm.getInstanceId() );
		List<Badge> badges = pm.loadAll(Badge.class);
		if ( errorSimulation ) {
			System.out.println("===== EXCEPTION for tests");
			throw new RuntimeException("Error simulation for tests");
		}
		return badges ;
	}
	
}
